﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using OpenRasta.Configuration;
using OpenRasta.IO;
using OpenRasta.Web;
using uREST.CMS.Handlers;
using uREST.CMS.Resources;
using uREST.Core;
using uREST.Core.Codecs;
using uREST.Core.Resources;
using uREST.Core.Services;

namespace uREST.CMS.Services
{
    public class MediaService : IuRESTService
    {
        public EndPoint EndPoint
        {
            get
            {
                return new EndPoint
                {
                    Name = "Media Service",
                    Description = "",
                    Href = typeof(List<Media>).CreateUri("MediaList").ToString()
                };
            }
        }

        public void RegisterHandlers()
        {
            ResourceSpace.Has.ResourcesOfType<List<Media>>()
                .AtUri(uRESTConfig.BaseUrl + "/media").Named("MediaList")
                .And.AtUri(uRESTConfig.BaseUrl + "/media?mediatypealias={mediaTypeAlias}").Named("MediaList")
                .And.AtUri(uRESTConfig.BaseUrl + "/media/{parentId}/media").Named("MediaList")
                .And.AtUri(uRESTConfig.BaseUrl + "/media/{parentId}/media?mediatypealias={mediaTypeAlias}").Named("MediaList")
                .HandledBy<MediaHandler>()
                .TranscodedBy<JsonNetCodec>();

            ResourceSpace.Has.ResourcesOfType<Media>()
               .AtUri(uRESTConfig.BaseUrl + "/media/{id}").Named("Media")
               .And.AtUri(uRESTConfig.BaseUrl + "/media/{id}?permanent={permanent}").Named("Media")
               .HandledBy<MediaHandler>()
               .TranscodedBy<JsonNetCodec>();
        }
    }
}
